import {
    createRouter,
    createWebHashHistory
} from "vue-router";
import login from '../components/login.vue'
import tab from "../components/tab.vue"
import zytz from '../components/zytz/index.vue'
import jkwd from '../components/jkwd/index.vue'
import sfwd from '../components/sfwd/index.vue'
import jtqy from '../components/jtqy/index.vue'
import sys  from '../components/zytz/sys.vue'
import souye from "../components/zytz/souye.vue"
import output from "../components/zytz/output.vue"
import ewm from "../components/jkwd/ewm.vue"
import inference from "../components/zytz/inference.vue"
import beiwang from "../components/zytz/beiwang.vue"
import jqr from "../components/jkwd/jqr.vue"
import smcs from "../components/jkwd/smcs.vue"
import txm from "../components/zytz/txm.vue"
const _isMobile = function () {
    const flag = navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
    )
    return flag
}
const routes = [{
        path: "/",
        redirect: "/login"

    },
    {
        path: "/login",
        name: "login",
        component: login,
    },
    {
        path: "/jqr",
        name: "jqr",
        component: jqr,
    },
    {
        path: "/tab",
        name: "tab",
        component:tab,
    },
    {
        path: "/zytz",
        name: "zytz",
        component:zytz,
    },
    {
        path: "/sys",
        name: "sys",
        component:sys,
    },
    {
        path: "/souye",
        name: "souye",
        component:souye,
    },
    {
        path: "/jtqy",
        name: "jtqy",
        component:jtqy
    },
    {
        path: "/sfwd",
        name: "sfwd",
        component:sfwd,
    },
    {
        path: "/jkwd",
        name: "jkwd",
        component:jkwd,
    },
    {
        path: "/ewm",
        name: "ewm",
        component:ewm,
    },
    {
        path: "/beiwang",
        name: "beiwang",
        component:beiwang,
    },
    
    {
        path: "/output",
        name: "output",
        component:output,
    },
    {
        path: "/inference",
        name: "inference",
        component:inference,
    },
    {
        path: "/smcs",
        name: "smcs",
        component:smcs,
    }
    ,
    {
        path: "/txm",
        name: "txm",
        component:txm,
    }

]
const router = createRouter({
    mode:"hash",
    history: createWebHashHistory(),
    routes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition || to) {
            // 如果之前有保存滚动位置，则直接滚动到该位置
            return savedPosition;
        } else {
            否则滚动到页面顶部
            return {
                top: 0
            };
        }
    },
})
router.beforeEach((to, from, next) => {
    window.scrollTo(0,1)
  if(to.name !== 'login'&& !(sessionStorage.getItem('item'))){
       next("/login")
    }
//     else if(to.name=="output"&&from.name=="souye"){
//         next(false)
//    }

//     else if(to.name=="sys"&&from.name!=="souye"){
//         next(false)
//    }else if(to.name=="tab"&&from.name!=="login"){
//          next(false)
//     }
    else {
    next()
    }
  })
export default router;